package com.xia.demo1;

import java.io.IOException;
import java.nio.file.*;

/**
 * Files工具类
 */
public class FilesTest {

    public static void main(String[] args) {

//        Path path = Paths.get("d:/test/test1.png");
//        boolean exists = Files.exists(path, new LinkOption[]{LinkOption.NOFOLLOW_LINKS});
//        System.out.println("文件是会否存在:" + exists);

        // 创建文件或者目录
        Path path = Paths.get("d:/test/test2/test3/test4");
//        try {
////            Path file = Files.createFile(path);
//            Path file = Files.createDirectories(path);
//
//        }  catch (FileAlreadyExistsException e){
//            System.out.println("exists");
//        }
//        catch (IOException e) {
//            e.printStackTrace();
//        }
        // 删除文件
//        try {
//            Files.delete(path);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        // 复制文件
//        Path source = Paths.get("d:/test/test1.png");
//        Path target = Paths.get("d:/test/test3.png");
//
//        try {
//            Files.copy(source,target);
//        } catch (FileAlreadyExistsException e) {
//            System.out.println("targetFile already exists");
//        } catch (IOException e){
//            System.out.println("other wrong");
//        }
        // 移动文件或者重命名
        Path source1 = Paths.get("d:/test/test1.png");
        Path target1 = Paths.get("d:/test/test4.png");
        try {
            Files.move(source1,target1);
        } catch (FileAlreadyExistsException e) {
            System.out.println("targetFile1 already exists");
        } catch (IOException e){
            System.out.println("other wrong");
        }






    }


}
